package sagroup.dracots;

import java.util.Date;
import java.util.Hashtable;
import java.util.concurrent.atomic.AtomicLong;

/**
 * The period used for adaptive engine to make decision. A period is
 * represented by a monotonically increasing sequential number and a
 * time stamp.
 * @author Zheng Xiang
 *
 */
public class Period {

	private static Hashtable<String,AtomicLong> count = new Hashtable<String, AtomicLong>();

	private long sequence;
	private Date time;

	private Period(String DSname) {
		if(!count.containsKey(DSname))
		{
			count.put(DSname, new AtomicLong(0));
		}
		
		sequence = count.get(DSname).addAndGet(1L);
		time = new Date();
	}

	public static Period createPeriod(String DSname) {
		return new Period(DSname);
	}

	public long getID() {
		return sequence;
	}
	
	public Date getTimeStamp() {
		return time;
	}
	
	public String toString()
	{
		return String.valueOf(this.sequence);
	}
}
